package com.framework.utils;

import com.framework.yhbEntity.view.CusTranView;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 封装类
 */
public class PackUtils {

    /**
     * 封装推荐商户列表
     * @param
     * @return
     */
    public static  List<CusTranView> packToCusTranView(List<Map<String,Object>> mapList,String dateColum) {

        List<CusTranView> ctvlist=new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        //获取列表第一天的月份
        int count=0;
        while (true){

            if(count==mapList.size()){
                break;
            }
            String dayTime=mapList.get(count).get(dateColum).toString();
            String time = sdf.format(DateUtils.stringToDate(dayTime,DateUtils.DATE_PATTERN));
            CusTranView smv=new CusTranView();
            smv.setTime(time);
            List<Map<String,Object>> temp=new ArrayList<>();
            String timeTemp;
            for (int i=count;i<mapList.size();i++){
                dayTime=mapList.get(count).get(dateColum).toString();
                timeTemp = sdf.format(DateUtils.stringToDate(dayTime,DateUtils.DATE_PATTERN));
                if(time.equals(timeTemp)){
                    temp.add(mapList.get(count));
                    count++;
                }
            }
            smv.setObjList(temp);
            ctvlist.add(smv);
        }
        return ctvlist;
    }
    /**
     * 封装收益列表
     * @param
     * @return
     */
    public static  List<CusTranView> packToCusTranView(List<Map<String,Object>> mapList,String dateColum,String pattern) {

        List<CusTranView> ctvlist=new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        BigDecimal bigDecimal;
        //获取列表第一天的月份
        int count=0;
        while (true){
            if(count==mapList.size()){
                break;
            }
            String dayTime=mapList.get(count).get(dateColum).toString();
            String time = sdf.format(DateUtils.stringToDate(dayTime,DateUtils.DATE_PATTERN));
            CusTranView smv=new CusTranView();
            bigDecimal = new BigDecimal("0.00");
            smv.setTime(time);
            List<Map<String,Object>> temp=new ArrayList<>();
            String timeTemp;
            for (int i=count;i<mapList.size();i++){
                dayTime=mapList.get(count).get(dateColum).toString();
                timeTemp = sdf.format(DateUtils.stringToDate(dayTime,DateUtils.DATE_PATTERN));
                if(time.equals(timeTemp)){
                    temp.add(mapList.get(count));
                    bigDecimal=bigDecimal.add(new BigDecimal(mapList.get(count).get("amount").toString()));
                    count++;
                }
            }
            smv.setObjList(temp);
            smv.setTotalAmount(bigDecimal);
            ctvlist.add(smv);
        }
        return ctvlist;
    }

}
